// ERROR: Not supported in C#: OptionDeclaration 
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.CodeRush.Core;
using System.Diagnostics;
using DX_Contrib;
using DX_Contrib.Controls;
using DX_Contrib.Painting;
//using DX_Contrib.Painting.Settings;
/// <summary>
/// Summary description for OptPaintIt.
/// </summary>
public class OptPaintIt : OptionsPage
{
    #region Constants
    public const string SECTION_CURRENT_MEMBER = "CurrentMember";
    public const string SECTION_DISPLAY_REFERENCE_COUNT = "ReferenceCount";
    public const string SECTION_TAB_REFERENCES = "TabNext";
    public const string SECTION_MEMBER_COLORS = "MemberColors";
    #endregion

    #region " private fields... "
    private Label label1;
    private LinkLabel paintItLink;
    private CheckBox chkReferenceCount;
    private GroupBox groupBox1;
    private CheckBox chkHighlightFoundItems;
    
    private System.ComponentModel.Container components = null;
    #endregion

    // constructor...
    public OptPaintIt()
        : base()
    {
        /// <summary>
        /// Required for Windows.Forms Class Composition Designer support
        /// </summary>
        InitializeComponent();
    }

    #region " CodeRush generated code "
    protected override void Initialize()
    {
        base.Initialize();

        CommitChanges += OptPaintIt_CommitChanges;
        PreparePage += OptPaintIt_PreparePage;
        RestoreDefaults += OptPaintIt_RestoreDefaults;

        paintItLink.Links.Add(new LinkLabel.Link(0, 20, "www.rorybecker.me.uk"));
    }

    public static string GetCategory()
    {
        return "Editor\\Navigation";
    }

    public static string GetPageName()
    {
        return "CountReferences";
    }

    public static DecoupledStorage Storage
    {
        get { return DevExpress.CodeRush.Core.CodeRush.Options.GetStorage(GetCategory(), GetPageName()); }
    }

    public override string Category
    {
        get { return OptPaintIt.GetCategory(); }
    }

    public override string PageName
    {
        get { return OptPaintIt.GetPageName(); }
    }

    public static new void Show()
    {
        DevExpress.CodeRush.Core.CodeRush.Command.Execute("Options", FullPath);
    }

    public static string FullPath
    {
        get { return GetCategory() + "\\" + GetPageName(); }
    }
    #endregion

    #region " Component Designer generated code "
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    internal System.Windows.Forms.TabControl TabControl1;
    internal System.Windows.Forms.TabPage tpCurrentMember;
    internal System.Windows.Forms.RadioButton optCurrentisCursor;
    internal System.Windows.Forms.RadioButton optCurrentisCaret;
    internal System.Windows.Forms.CheckBox chkCurrentMemberEnabled;
    internal System.Windows.Forms.CheckBox chkHighlightCurrentItem;
    internal PaintPicker CurrentPaintPicker;
    private void InitializeComponent()
    {
        this.TabControl1 = new System.Windows.Forms.TabControl();
        this.tpCurrentMember = new System.Windows.Forms.TabPage();
        this.chkReferenceCount = new System.Windows.Forms.CheckBox();
        this.paintItLink = new System.Windows.Forms.LinkLabel();
        this.label1 = new System.Windows.Forms.Label();
        this.chkHighlightCurrentItem = new System.Windows.Forms.CheckBox();
        this.chkCurrentMemberEnabled = new System.Windows.Forms.CheckBox();
        this.optCurrentisCaret = new System.Windows.Forms.RadioButton();
        this.optCurrentisCursor = new System.Windows.Forms.RadioButton();
        this.CurrentPaintPicker = new DX_Contrib.Controls.PaintPicker();
        this.chkHighlightFoundItems = new System.Windows.Forms.CheckBox();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.TabControl1.SuspendLayout();
        this.tpCurrentMember.SuspendLayout();
        this.groupBox1.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
        this.SuspendLayout();
        // 
        // TabControl1
        // 
        this.TabControl1.Controls.Add(this.tpCurrentMember);
        this.TabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.TabControl1.Location = new System.Drawing.Point(0, 0);
        this.TabControl1.Name = "TabControl1";
        this.TabControl1.SelectedIndex = 0;
        this.TabControl1.Size = new System.Drawing.Size(530, 480);
        this.TabControl1.TabIndex = 5;
        // 
        // tpCurrentMember
        // 
        this.tpCurrentMember.Controls.Add(this.groupBox1);
        this.tpCurrentMember.Controls.Add(this.chkReferenceCount);
        this.tpCurrentMember.Controls.Add(this.paintItLink);
        this.tpCurrentMember.Controls.Add(this.label1);
        this.tpCurrentMember.Controls.Add(this.chkCurrentMemberEnabled);
        this.tpCurrentMember.Controls.Add(this.optCurrentisCaret);
        this.tpCurrentMember.Controls.Add(this.optCurrentisCursor);
        this.tpCurrentMember.Location = new System.Drawing.Point(4, 22);
        this.tpCurrentMember.Name = "tpCurrentMember";
        this.tpCurrentMember.Size = new System.Drawing.Size(522, 454);
        this.tpCurrentMember.TabIndex = 2;
        this.tpCurrentMember.Text = "Current Member";
        // 
        // chkReferenceCount
        // 
        this.chkReferenceCount.AutoSize = true;
        this.chkReferenceCount.Location = new System.Drawing.Point(72, 110);
        this.chkReferenceCount.Name = "chkReferenceCount";
        this.chkReferenceCount.Size = new System.Drawing.Size(144, 17);
        this.chkReferenceCount.TabIndex = 11;
        this.chkReferenceCount.Text = "Display Reference Count";
        this.chkReferenceCount.UseVisualStyleBackColor = true;
        // 
        // paintItLink
        // 
        this.paintItLink.AutoSize = true;
        this.paintItLink.Location = new System.Drawing.Point(203, 397);
        this.paintItLink.Name = "paintItLink";
        this.paintItLink.Size = new System.Drawing.Size(59, 13);
        this.paintItLink.TabIndex = 10;
        this.paintItLink.TabStop = true;
        this.paintItLink.Text = "Homepage";
        this.paintItLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.paintItLink_LinkClicked);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(12, 397);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(185, 13);
        this.label1.TabIndex = 9;
        this.label1.Text = "Original PaintIt plug-in by Rory Becker";
        // 
        // chkHighlightCurrentItem
        // 
        this.chkHighlightCurrentItem.Location = new System.Drawing.Point(15, 24);
        this.chkHighlightCurrentItem.Name = "chkHighlightCurrentItem";
        this.chkHighlightCurrentItem.Size = new System.Drawing.Size(128, 24);
        this.chkHighlightCurrentItem.TabIndex = 6;
        this.chkHighlightCurrentItem.Text = "Highlight current item";
        // 
        // chkCurrentMemberEnabled
        // 
        this.chkCurrentMemberEnabled.Location = new System.Drawing.Point(40, 24);
        this.chkCurrentMemberEnabled.Name = "chkCurrentMemberEnabled";
        this.chkCurrentMemberEnabled.Size = new System.Drawing.Size(104, 24);
        this.chkCurrentMemberEnabled.TabIndex = 4;
        this.chkCurrentMemberEnabled.Text = "Enabled";
        // 
        // optCurrentisCaret
        // 
        this.optCurrentisCaret.Location = new System.Drawing.Point(72, 56);
        this.optCurrentisCaret.Name = "optCurrentisCaret";
        this.optCurrentisCaret.Size = new System.Drawing.Size(208, 24);
        this.optCurrentisCaret.TabIndex = 1;
        this.optCurrentisCaret.Text = "Current Under Caret";
        // 
        // optCurrentisCursor
        // 
        this.optCurrentisCursor.Location = new System.Drawing.Point(72, 80);
        this.optCurrentisCursor.Name = "optCurrentisCursor";
        this.optCurrentisCursor.Size = new System.Drawing.Size(208, 24);
        this.optCurrentisCursor.TabIndex = 0;
        this.optCurrentisCursor.Text = "Current Under Cursor";
        // 
        // CurrentPaintPicker
        // 
        this.CurrentPaintPicker.Decoration = DX_Contrib.Painting.PaintRequestEnum.BrushStroke;
        this.CurrentPaintPicker.Location = new System.Drawing.Point(15, 54);
        this.CurrentPaintPicker.Name = "CurrentPaintPicker";
        this.CurrentPaintPicker.Size = new System.Drawing.Size(286, 24);
        this.CurrentPaintPicker.TabIndex = 8;
        // 
        // chkHighlightFoundItems
        // 
        this.chkHighlightFoundItems.Location = new System.Drawing.Point(149, 24);
        this.chkHighlightFoundItems.Name = "chkHighlightFoundItems";
        this.chkHighlightFoundItems.Size = new System.Drawing.Size(104, 24);
        this.chkHighlightFoundItems.TabIndex = 13;
        this.chkHighlightFoundItems.Text = "Highlight found";
        // 
        // groupBox1
        // 
        this.groupBox1.Controls.Add(this.CurrentPaintPicker);
        this.groupBox1.Controls.Add(this.chkHighlightFoundItems);
        this.groupBox1.Controls.Add(this.chkHighlightCurrentItem);
        this.groupBox1.Location = new System.Drawing.Point(72, 133);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(296, 107);
        this.groupBox1.TabIndex = 14;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "Highlight Options";
        // 
        // OptPaintIt
        // 
        this.Controls.Add(this.TabControl1);
        this.Name = "OptPaintIt";
        this.TabControl1.ResumeLayout(false);
        this.tpCurrentMember.ResumeLayout(false);
        this.tpCurrentMember.PerformLayout();
        this.groupBox1.ResumeLayout(false);
        ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
        this.ResumeLayout(false);

    }
    #endregion

    // protected methods...
    #region " Dispose "
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if ((components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
    }
    #endregion
    public static DX_Contrib.Painting.PaintOptions DefaultHighlightStyle()
    {
        return new DX_Contrib.Painting.PaintOptions(PaintRequestEnum.BrushStroke, Color.Blue, 100, Color.Blue, 255);
    }
    public static DX_Contrib.Painting.PaintOptions DefaultMemberStyle()
    {
        return new DX_Contrib.Painting.PaintOptions(PaintRequestEnum.TextOverlay, Color.Black, 255, Color.Gray, 255);
    }

    private void OptPaintIt_PreparePage(object sender, DevExpress.CodeRush.Core.OptionsPageStorageEventArgs ea)
    {
        try
        {
            chkCurrentMemberEnabled.Checked = Storage.ReadBoolean(SECTION_CURRENT_MEMBER, "Enabled", true);
            chkReferenceCount.Checked = Storage.ReadBoolean(SECTION_DISPLAY_REFERENCE_COUNT, "DisplayReferenceCount", true);
            optCurrentisCaret.Checked = ea.Storage.ReadBoolean(SECTION_CURRENT_MEMBER, "CurrentUnderCaret", true);
            optCurrentisCursor.Checked = ea.Storage.ReadBoolean(SECTION_CURRENT_MEMBER, "CurrentUnderCursor", false);
            chkHighlightCurrentItem.Checked = ea.Storage.ReadBoolean(SECTION_CURRENT_MEMBER, "HighlightCurrentItem", true);
            chkHighlightFoundItems.Checked = Storage.ReadBoolean(SECTION_CURRENT_MEMBER, "HighlightOtherItems", true);

            DX_Contrib.Painting.Settings.LoadStyle(Storage, SECTION_CURRENT_MEMBER, "", CurrentPaintPicker, DefaultHighlightStyle());

            DX_Contrib.Painting.PaintOptions HighlightStyle = DefaultMemberStyle();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
            throw;
        }

    }
    private void OptPaintIt_CommitChanges(object sender, DevExpress.CodeRush.Core.OptionsPageStorageEventArgs ea)
    {
        try
        {
            ea.Storage.WriteBoolean(SECTION_CURRENT_MEMBER, "HighlightCurrentItem", chkHighlightCurrentItem.Checked);
            ea.Storage.WriteBoolean(SECTION_CURRENT_MEMBER, "HighlightOtherItems", chkHighlightFoundItems.Checked);
            ea.Storage.WriteBoolean(SECTION_DISPLAY_REFERENCE_COUNT, "DisplayReferenceCount", chkReferenceCount.Checked);
            ea.Storage.WriteBoolean(SECTION_CURRENT_MEMBER, "Enabled", chkCurrentMemberEnabled.Checked);

            ea.Storage.WriteBoolean(SECTION_CURRENT_MEMBER, "CurrentUnderCaret", optCurrentisCaret.Checked);
            ea.Storage.WriteBoolean(SECTION_CURRENT_MEMBER, "CurrentUnderCursor", optCurrentisCursor.Checked);

            DX_Contrib.Painting.Settings.SaveStyle(ea.Storage, SECTION_CURRENT_MEMBER, "", CurrentPaintPicker);
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
            throw;
        }
    }
    private void OptPaintIt_RestoreDefaults(object sender, DevExpress.CodeRush.Core.OptionsPageEventArgs ea)
    {
        chkCurrentMemberEnabled.Checked = true;
        chkHighlightCurrentItem.Checked = true;
        chkReferenceCount.Checked = true;
        chkHighlightFoundItems.Checked = true;

        Settings.Copy(DefaultMemberStyle(), CurrentPaintPicker);

        optCurrentisCaret.Checked = true;
        optCurrentisCursor.Checked = false;

        DX_Contrib.Painting.PaintOptions HighlightStyle = DefaultMemberStyle();
    }

    private void paintItLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
    }
}
